#!/usr/bin/python2
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 CourseRoster contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


__author__ = "antiAgainst@gmail.com"


#import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')


class CourseDict(object):
    """ course-uuid <--> course-name dict """


    def __init__ (self, stdid=None):
        self.stdid = "none"
        self.courses = {}
        if stdid: self.stdid = stdid

    def __str__(self):
        ret = "\n[studentID]%s:\n" % self.stdid
        for c in self.courses:
            ret += "[course]%s -+- [uuid]%s\n" % (self.courses[c], c)
        ret += "*" * 8 + " total: %d " % len(self.courses) + "*" * 8
        ret += "\n\n"
        return ret.encode("utf-8")

    def __len__(self):
        return len(self.courses)

    def __getitem__(self, index):
        return self.courses[index]

    def __setitem__(self, index, value):
        self.courses[index] = value

    def keys(self):
        return self.courses.keys()

    def values(self):
        return self.courses.values()

    def items(self):
        return self.courses.items()

class RosterAlbum(object):
    """ 
    course <--> course-roster dict 
    course-roster is a course-userid <--> (classmate, email) dict
    """


    def __init__(self, stdid=None):
        self.stdid = "none"
        self.rstalb = {}
        if stdid: self.stdid = stdid

    def __str__(self):
        ret = "\n[studentID]%s:\n" % self.stdid
        for c in self.rstalb:
            ret += "[course]%s:\n" % c
            for i in self.rstalb[c]:
                ret += "[crsusr-id]%s -+- " % i
                ret += "[classmate]%s -+- [email]%s\n" \
                        % self.rstalb[c][i]
            ret += "*" * 8 + " total: %d" % len(self.rstalb[c])
            ret += "*" * 8 + "\n\n"
        return ret.encode("utf-8")
        
    def __len__(self):
        return len(self.rstalb)

    def __getitem__(self, index):
        return self.rstalb[index]

    def __setitem__(self, index, value):
        self.rstalb[index] = value


__all__ = ["CourseDict", "RosterAlbum"]
